public class Solution {
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        int count = 0;
        if (flowerbed == null || flowerbed.length == 0 || flowerbed.length <= n) {
            return false;
        }
        for (int i = 0; i < flowerbed.length; i++) {

            if (i == 0 && flowerbed[0] == 0 && flowerbed[1] == 0) {
                flowerbed[0] = 1;
                count++;
            }
            if (flowerbed[i] == 0 && i != flowerbed.length-1&& flowerbed[i+1] == 0 && flowerbed[i - 1] == 0 ) {
                flowerbed[i] = 1;
                count++;
            }
            if (i == flowerbed.length-1 && flowerbed[i] == 0 && flowerbed[i - 1] == 0 ) {
                flowerbed[i] = 1;
                count++;
            }
        }
        return count == n;
    }
}
